/************************************
 * Package: RGcpp					*
 * Authors: Rui Eduardo Gouveia Gil	*
 * Date: 2010						*
 ************************************/
#ifndef __RGCPP_TOHEX_H__
#define __RGCPP_TOHEX_H__

#include <string>
#include <sstream>
#include <iostream>
#include <typeinfo>

#include "rgcpp/exceptions/RuntimeException.h"

namespace rgcpp
{

static const char* HEX_CONVERT_STR = "0123456789ABCDEF";

inline std::string ToHex(const char* buffer, unsigned int size)
{
	std::stringstream stream;

	for(unsigned int i=0; i<size; i++)
	{
		stream << HEX_CONVERT_STR[((buffer[i] >> 4) & 0xF)];
		stream << HEX_CONVERT_STR[((buffer[i] >> 0) & 0xF)];
	}

	std::string result = stream.str();
	return result;
}

inline void ToHex(char* rbuffer, const char* sbuffer, unsigned int size)
{
	for(unsigned int i=0; i<size; i++)
	{
		rbuffer[i+i+0] = HEX_CONVERT_STR[((sbuffer[i] >> 4) & 0xF)];
		rbuffer[i+i+1] = HEX_CONVERT_STR[((sbuffer[i] >> 0) & 0xF)];
	}
}

}

#endif
